package com.example.gustavo.hello.activity;

import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.example.gustavo.hello.R;

public class AnimationActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation);

        View ll_bg = findViewById(R.id.ll_bg);
        ImageView iv_pointer = (ImageView) findViewById(R.id.iv_pointer);


        Animation animation = AnimationUtils.loadAnimation(this, R.anim.ani_radar);
        animation.setAnimationListener(new Animation.AnimationListener() {


            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        iv_pointer.startAnimation(animation);

        int startColor = Color.parseColor("#00ff00");
        System.out.println("startColor = " + startColor);
        int endColor = Color.parseColor("#ff0000");
        System.out.println("endColor = " + endColor);
        ObjectAnimator animator = ObjectAnimator.ofObject(ll_bg, "backgroundColor", new ArgbEvaluator(), startColor, endColor);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {

                Object animatedValue = animation.getAnimatedValue();
                System.out.println("animatedValue = " + animatedValue);
            }
        });
        animator.setDuration(5000);
        animator.start();


    }
}
